Scripting provides a set of convenient time-related label components that wrap SwiftUI's Text styles. These components allow you to display live-updating or formatted date and time strings in widgets and views, with support for dynamic behaviors like relative time and timers.
DateLabelDisplays a dynamic label representing a single point in time using a specified style. This is ideal for widgets that need to show time-based data even when not actively running.
timestamp: A UNIX timestamp in milliseconds representing the date to be
style: The display style. Can be:
"date": e.g. "June 3, 2019"
"time": e.g. "11:23PM"
"timer": a running timer string
"relative": e.g. "2 hours, 23 minutes"
"offset": e.g. +2 hours, -3 months
DateRangeLabelDisplays a localized textual representation of a time range between two dates.
| Property | Description |
|---|---|
from |
The start date timestamp in milliseconds. |
to |
The end date timestamp in milliseconds. |
DateIntervalLabelDisplays a formatted time interval, typically between two times on the same day (e.g., for event scheduling).
Same as DateRangeLabelProps:
Output example: "9:30 AM – 3:30 PM"
TimerIntervalLabelDisplays a live-updating timer counting up or down between two timestamps. Optionally, the timer can pause at a specific point.
| Property | Description |
|---|---|
from |
Start timestamp of the interval. |
to |
End timestamp of the interval. |
pauseTime |
(Optional) A timestamp at which the timer should pause. If undefined, the timer runs to completion. |
countsDown |
(Optional) Whether to count down. Defaults to true. |
showsHours |
(Optional) Whether to show the hour component when over 60 minutes. Defaults to true. |
This displays a countdown from 12 minutes and pauses at the 10-minute mark.